package com.sc.VenusQueryBeta.presenter.account.changmian;

import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.account.changmian.ChangMianContract;
import com.sc.VenusQueryBeta.model.account.changmian.ChangMianModel;
import com.sc.VenusQueryBeta.model.bean.account.AllRoomListBean;
import com.sc.VenusQueryBeta.model.bean.account.CurrencyListBean;
import com.sc.VenusQueryBeta.model.bean.account.MaxChangemonthBean;
import com.sc.VenusQueryBeta.model.bean.account.changmian.ChangMianPopBean;
import com.sc.VenusQueryBeta.model.bean.account.changmian.ChangmianBean;

import io.reactivex.functions.Consumer;


/**
 * Created by SC-02 on 2018/9/19.
 * 场面明细presenter 继承契约类的presenper
 */

public class ChangMianPresenter extends ChangMianContract.ChangMianPresenter {
    @Override
    protected ChangMianContract.IChangMianModel getModel() {
        return ChangMianModel.newInstance();
    }

    @Override
    public void onStart() {

    }
    /**
     * 实例化对象
     */
    public static ChangMianPresenter newInstance(){
        return new ChangMianPresenter();
    }

//    /**
//     * 查询厅
//     * @param serverAddress
//     * @param projectName
//     * @param serverPort
//     */
//    @Override
//    public void queryAllRoomList(String serverAddress, String projectName, int serverPort) {
//        if (mIView == null || mIModel == null)
//            return;
//        mRxManager.register(mIModel.queryAllRoomList(serverAddress,projectName,serverPort).subscribe(new Consumer<AllRoomListBean>() {
//            @Override
//            public void accept(AllRoomListBean allRoomListBean) throws Exception {
//                mIView.showqueryAllRoomList(allRoomListBean);
//            }
//        }, new Consumer<Throwable>() {
//            @Override
//            public void accept(Throwable throwable) throws Exception {
//                LogUtils.e("查询厅Network error."+throwable.getMessage());
//                mIView.showToast("Network error.");
//                mIView.showAllRoomNetworkError(throwable);
//            }
//        }));
//    }

    @Override
    public void queryAllCurrencyList(String serverAddress, String projectName, int serverPort) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.queryAllCurrencyList(serverAddress,projectName,serverPort).subscribe(new Consumer<CurrencyListBean>() {
            @Override
            public void accept(CurrencyListBean currencyListBean) throws Exception {
                mIView.showqueryAllCurrencyList(currencyListBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("查询厅Network error."+throwable.getMessage());
                mIView.showToast("Network error.");
                mIView.showAllCurrencyNetworkError(throwable);
            }
        }));
    }

    /**
     * 场面明细
     * @param serverAddress
     * @param projectName
     * @param serverPort
     * @param clientindex
     * @param roommonth
     * @param roomyear
     * @param currencynameCN
     */
    @Override
    public void queryClientWinnumMessage(String serverAddress, String projectName, int serverPort, int clientindex, String roommonth, String roomyear, String currencynameCN) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.queryClientWinnumMessage(serverAddress,projectName,serverPort,clientindex,roommonth,roomyear,currencynameCN).subscribe(new Consumer<ChangmianBean>() {
            @Override
            public void accept(ChangmianBean changmianBean) throws Exception {
//                if (mIView != null)
                mIView.showChangMianDataSuccess(changmianBean);

            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("场面error=="+throwable.getMessage());
                mIView.showToast("Network error");
                mIView.showNetworkError(throwable);
            }
        }));
    }

//    /**
//     * 查詢最大日期
//     * @param serverAddress
//     * @param projectName
//     * @param serverPort
//     * @param roomid
//     */
//    @Override
//    public void queryMaxChangemonth(String serverAddress, String projectName, int serverPort, int roomid) {
//        if (mIView == null || mIModel == null)
//            return;
//        mRxManager.register(mIModel.queryMaxChangemonth(serverAddress,projectName,serverPort,roomid).subscribe(new Consumer<MaxChangemonthBean>() {
//            @Override
//            public void accept(MaxChangemonthBean allRoomListBean) throws Exception {
//                if (mIView != null) {
//                    mIView.showMaxChangemonthList(allRoomListBean);
//                } else {
//                    LogUtils.e(" view = null");
//                }
//            }
//        }, new Consumer<Throwable>() {
//            @Override
//            public void accept(Throwable throwable) throws Exception {
//                LogUtils.e("Network error.00"+throwable.getMessage());
//                mIView.showNetworkError(throwable);
//                mIView.showToast("Network error." + throwable.getMessage());
//            }
//        }));
//    }

    //场面弹出框
    @Override
    public void changmianpop(String serverAddress, String projectName, int serverPort, int winnumindex) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.changmianpop(serverAddress,projectName,serverPort,winnumindex).subscribe(new Consumer<ChangMianPopBean>() {
            @Override
            public void accept(ChangMianPopBean changMianPopBean) throws Exception {
                if (mIView != null) {
                    mIView.showChangMianPopSuccess(changMianPopBean);
                } else {
                    LogUtils.e(" view = null");
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e(" pop Network error."+throwable.getMessage());
                mIView.showToast("Network error."+throwable.getMessage());
                mIView.showNetworkError(throwable);
            }
        }));
    }
}
